home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 114_01.zip / CONFIG3.BDS < prev    next >
Text File  |  1993-06-01  |  2KB  |  99 lines

  1. /* Screen editor configurator:  general utilities
  2.  *
  3.  * Source:  config3.bds
  4.  * Version: December 20, 1981.
  5.  */
  6.  
  7. #include bdscio.h
  8. #include config.h
  9.  
  10. /* return: is first token in args a number ? */
  11. /* return value of number in *val            */
  12.  
  13. number(args,val) char *args; int *val;
  14. {
  15. char c;
  16.     c=*args++;
  17.     if (c<'0' || c>'9') {
  18.         return(NO);
  19.     }
  20.     *val=c-'0';
  21.     while (c=*args++) {
  22.         if (c<'0' || c>'9') {
  23.             break;
  24.         }
  25.         *val=(*val*10)+c-'0';
  26.     }
  27.     return(YES);
  28. }
  29.  
  30. /* convert character buffer to numeric */
  31.  
  32. ctoi(buf,index) char *buf; int index;
  33. {
  34. int k;
  35.     while ( (buf[index]==' ') +
  36.         (buf[index]==TAB) ) {
  37.         index++;
  38.     }
  39.     k=0;
  40.     while (buf[index]>='0' && buf[index]<='9') {
  41.         k=(k*10)+buf[index]-'0';
  42.         index++;
  43.     }
  44.     return(k);
  45. }
  46.  
  47. /* put decimal integer n in field width >= w */
  48.  
  49. putdec(n,w) int n,w;
  50. {
  51. char chars[10];
  52. int i,nd;
  53.     nd=itoc(n,chars,10);
  54.     i=nd;
  55.     while (i++<w) {
  56.         putchar(' ');
  57.     }
  58.     i=0;
  59.     while (i<nd) {
  60.         putchar(chars[i++]);
  61.     }
  62. }
  63.  
  64. /* convert integer n to character string in str */
  65.  
  66. itoc(n,str,size) int n; char *str; int size;
  67. {
  68. int absval;
  69. int len;
  70. int i,j,k;
  71.     absval=abs(n);
  72.     /* generate digits */
  73.     str[0]=0;
  74.     i=1;
  75.     while (i<size) {
  76.         str[i++]=(absval%10)+'0';
  77.         absval=absval/10;
  78.         if (absval==0) {
  79.             break;
  80.         }
  81.     }
  82.     /* generate sign */
  83.     if (i<size && n<0) {
  84.         str[i++]='-';
  85.     }
  86.     len=i-1;
  87.     /* reverse sign, digits */
  88.     i--;
  89.     j=0;
  90.     while (j<i) {
  91.         k=str[i];
  92.         str[i]=str[j];
  93.         str[j]=k;
  94.         i--;
  95.         j++;
  96.     }
  97.     return(len);
  98. }
  99. acte